<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="utils.StringUtils" %>
<%@ page import="database.*" %>
<%@ page import="java.text.DecimalFormat" %>
<%--
  Created by IntelliJ IDEA.
  User: Thinkpad
  Date: 2016/12/8
  Time: 21:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>评价管理</title>
    <link rel="stylesheet" href="../../static/style/weui.css"/>
    <link rel="stylesheet" href="../../static/example/example.css"/>
    <link rel="stylesheet" href="../../static/style/myStyle.css"/>
    <%
        int pageNumber = 1;
        final int pageSize = 10;
        int maxPage = (int) Math.ceil(CourseDb.selectCoursesAfterDurationCount(0, 999) * 1.0f / pageSize);
        if (!StringUtils.isEmpty(request.getParameter("page"))) {
            pageNumber = Integer.parseInt(request.getParameter("page"));
        }
        List<Course> courses = new ArrayList<Course>();
        courses = CourseDb.selectCourses((pageNumber - 1) * pageSize, pageSize);
    %>
</head>
<body style="background-color: transparent;color: #ffffff;">
<%@include file="Do/checkAdminLogin.jsp"%>
<br><br>
<h1 class = "page_title">评价</h1>
<table class='zebra' style='table-layout:fixed'>
    <tr>
        <th style='width:30%'>课程</th>
        <th style='width:13%'>课程内容</th>
        <th style='width:13%'>教师水平</th>
        <th style='width:13%'>所得收获</th>
        <th style='width:30%'>评语</th>
        <th style='width:30%'>退课理由</th>
    </tr>
    <%
        DecimalFormat format = new DecimalFormat("#.00");
        for (int i = 0; i < courses.size(); i++) {
            Course course = courses.get(i);
            int courseId = course.getId();
            String courseName = course.getName();
            float[] comment = CommentDb.selectAvgRatingByCourseId(courseId);
            List<CourseComment> commentWords = CommentDb.selectCommentsByCourseId(courseId, 0, 999);
            List<Comment> quitReasons = CommentDb.selectQuitReasonsByCourseId(courseId, 0, 999);
    %>
    <tr>
        <td><%=courseName%></td>
        <td><%=StringUtils.parseFloat(comment[0])%></td>
        <td><%=StringUtils.parseFloat(comment[1])%></td>
        <td><%=StringUtils.parseFloat(comment[2])%></td>
        <td><a href='comments.jsp?courseId=<%=courseId%>'><%=commentWords.size()>0?commentWords.get(commentWords.size()-1).getComment():"暂无评语"%></a></td>
        <td><a href='quitReasons.jsp?courseId=<%=courseId%>'><%=quitReasons.size()>0?quitReasons.get(quitReasons.size()-1).getComment():"暂无理由"%></a></td>
    </tr>
<%}%>
</table>
<br><br>
<div id="buttons" align="center">
    <%
        if(pageNumber != 1) {
    %>
    <button class="weui_btn weui_btn_mini weui_btn_plain_default" style="position: relative"
            onclick="onPreviousPage(<%=pageNumber%>)">上一页
    </button>&nbsp;&nbsp;&nbsp;
    <%
        }
    %>
    <%
        if(pageNumber != maxPage) {
    %>
    <button class="weui_btn weui_btn_mini weui_btn_plain_default" style="position: relative"
            onclick="onNextPage(<%=pageNumber%>,<%=maxPage%>)">下一页
    </button>
    <%
        }
    %>

</div><br>
<div style="text-align: center;">
<button class="greyBtn" style = "position: relative" onclick="clickExport()">导出表格...</button>
</div>
</body>
<script>
    function clickExport(){
        location.href='exportCommentTable';
    }
    function onPreviousPage(page){
        if(page>=2)
            page--;
        location.href = 'rating.jsp?page='+page;
    }
    function onNextPage(page, maxPage){
        if(page<maxPage)
            page++;
        location.href = 'rating.jsp?page='+page;
    }
</script>
</html>